import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:little_painter/custom_widget/keep_alive_wrapper.dart';

import '../../../utils/logger_utils.dart';
import '../../bottom_page1/bottom_page1.dart';
import '../../bottom_page2/bottom_page2.dart';
import '../../bottom_page3/bottom_page3.dart';
import '../../test/test_function_page.dart';

/// 主页控制器
class LittlePainterController extends GetxController {
  int testCount = 0;

  void setTestCount() async {
    testCount++;
    update();
  }

  /// 底部导航索引
  int currentIndex = 0;

  /// PageView 控制器
  PageController pageController = PageController();

  /// 设置底部导航索引
  void setCurrentIndex(int index) async {
    currentIndex = index;
    pageController.jumpToPage(currentIndex);
    update();
  }

  /// 底部导航页-切换页面
  final bottomNavigationPages = [
    const KeepAliveWrapper(keepAlive: true, child: BottomPage1()),
    const KeepAliveWrapper(keepAlive: true, child: BottomPage2()),
    const KeepAliveWrapper(keepAlive: true, child: BottomPage3()),
    const KeepAliveWrapper(keepAlive: true, child: TestFunctionPage()),
  ];

  /// 底部导航-图标和文字定义
  final bottomNavigationBarItems = [
    const BottomNavigationBarItem(
      icon: Icon(Icons.home),
      label: 'page1',
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.find_in_page),
      label: 'page2',
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.shop),
      label: 'page3',
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.tungsten_sharp),
      label: 'test',
    ),
  ];

  @override
  void onInit() {
    LogUtils.d('LittlePainterController onInit');
    super.onInit();
  }

  @override
  void onReady() {
    LogUtils.d('LittlePainterController onReady');
    super.onReady();
  }

  @override
  void onClose() {
    LogUtils.d('LittlePainterController onClose');
    super.onClose();
  }
}
